package com.ncloud.crm.mapper;

import com.ncloud.crm.entity.MsgBox;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by shiqiang on 2017/7/7.
 */
@Mapper
public interface MsgBoxMapper {
    @Insert("insert into pub_message_box(msg_id, msg_type, msg_name, msg_content, create_time)"
            + " values(#{msgId}, #{msgType}, #{msgName}, #{msgContent}, #{createTime})")
    public int insertMessage(MsgBox msgBox);

    @Insert("insert into pub_msgbox_user(msg_id, user_id, msg_state)"
            + " values(#{msgId}, #{userId}, #{msgState})")
    public int insertUserMsg(MsgBox msgBox);

    @Select(value = { "select a.*,b.user_id,b.msg_state from pub_msgbox_user b, pub_message_box a where a.msg_id =b.msg_id and b.user_id =#{userId}" })
    @Results({ @Result(column = "msg_id", property = "msgId"),
            @Result(column = "msg_type", property = "msgType"),
            @Result(column = "msg_name", property = "msgName"),
            @Result(column = "msg_content", property = "msgContent"),
            @Result(column = "msg_state", property = "msgState"),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "create_time", property = "createTime")
    })
    public List<MsgBox> getMsgUsers(@Param("workId") Long userId);
}
